package edu.gyc.ly.controller;

import edu.gyc.ly.model.Report;
import edu.gyc.ly.util.ConvertUpMoney;
import edu.gyc.ly.util.MyWordUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Controller
public class WordController {
    @RequestMapping("export")
    public void export(HttpServletRequest request, HttpServletResponse response, Report report) {
        Map<String, Object> params = new HashMap<>();
//        params.put("title","这是标题");
//        params.put("name","李四");
        params.put("cgbm", report.getCgbm());
        params.put("htbh", report.getHtbh());
        params.put("djq", report.getDjq());
        params.put("money", report.getMoney());
//        params.put("dxmoney", report.getDxmoney());
        params.put("dxmoney", ConvertUpMoney.toChinese(report.getMoney() + ""));
        params.put("zbsj", report.getZbsj());
        params.put("fps", report.getFps());
        params.put("fpqd", report.getFpqd());
        params.put("gsht", report.getGsht());
        params.put("gjy", report.getGjy());
        params.put("zbtzs", report.getZbtzs());
        params.put("cgqdyj", report.getCgqdyj());
        params.put("cgqdyjy", report.getCgqdyjy());
        params.put("cgqs", report.getCgqs());
        params.put("cgqsy", report.getCgqsy());
        params.put("gzkyssx", report.getGzkyssx());
        params.put("rkd", report.getRkd());

        Calendar now = Calendar.getInstance();

        params.put("year", now.get(Calendar.YEAR));
        params.put("month", (now.get(Calendar.MONTH) + 1));
        params.put("day", now.get(Calendar.DAY_OF_MONTH));
        log.info("ly input: " + params.toString());
        //这里是我说的一行代码
        try {
            MyWordUtil.exportWord("word/fksq.docx", "d:/test", "ly.docx", params, request, response);

        } catch (Exception e) {
            log.error(e.toString());
        }
    }
}
